#!/bin/bash
#========================================================================
# Author: YSLin
# Email: 
# File Name: deleteTheLast6Lines.sh
# Description: 
#   
# Edit History: 
#   2011-02-24    File created.
#========================================================================


#Steps [1] thru [6] constitute a loop. When sed exits this loop, PS will contains Line 1 thru 6 of the processed file. For files containing less than 6 lines, they will be discarded by the command 'd' in step [3] .
#When Line 6 of the file has been read, unless the last line is reached, we will each time
#  Append one next line to PS.
#  Print the first line in PS.
#  Remove the first line in PS.
#When the last line has been read, PS contains all the last 6 lines of the processed file, all we have to do is discarding them via command 'd' in [7].
sed '
:loop
1,5{
$d
N
b loop
}
$d
N
P
D
' line.txt

#This is a refined version of Script1.
#Be careful! The address in Step [4] is 2,6 rather than 1,5, which is used in Step [2] of Script1.
sed '
:loop
$d
N
2,6b loop
P
D
' line.txt
